<?php
include_once('../includes/definer.php');
include_once(INC.'admin/php/bootstrap.php');
include_once(INC.'admin/php/clases/FileImage.php');

//INFO
$about = About::getInstance();
$about->me = $_POST['me'];
$clients = explode('|', $_POST['clients']);
$about->clients->delete();
foreach ($clients as $c) {
    $client = new Client();
    $client->value = $c;
    $about->clients[] = $client;
}

//IMAGENES
$n = (Imagen::lastId())?Imagen::lastId()+1:1;//numero al final de la imagen (Ej: imagen.1.jpg, imagen.2.jpg)
$origen = INC.'content/tmp/about/';
$destino = INC.'content/about/';
if (isset($_POST['newImages']) && count($_POST['newImages'])) {
    foreach ($_POST['newImages'] as $newImage) {
        $data = explode(',', $newImage);

        //Imagen  original
        if (copy($origen.$data[0].'.'.$data[2], $destino.'about.'.$n.'.'.$data[2])) {
            unlink($origen.$data[0].'.'.$data[2]);
        }

        //Creo el objeto imagen y se lo asigno al producto
        $imagen = new Imagen();
        $imagen->src = 'about.'.$n.'.'.$data[2];
        $imagen->orden = $data[1];
        $about->imagenes[] = $imagen;
        $n++;
    }
}
$about->save();
header('location: '.URL.'admin/about#success');
?>
